* Replication do file for Rune Stubager, 'How are social groups linked to the vote? Social group perceptions and party choice', British Journal of Political Science

* This file replicates the main experimental analyses of the paper 

* Load data
use ".../social_groups_vote_expt_data.dta", clear

* Analyses

* Figure 3 
* A: Working class sympathy

eststo wcsym: reg q6 i.Splitgroup1##i.Splitgroup2 if q3 !=2
margins, at(Splitgroup1=(0 1)) over(Splitgroup2) post
mat symp = e(b)'

foreach b of numlist 1/4 {
	scalar define lo`b' = e(b)[1,`b'] - sqrt(e(V)[`b',`b'])*invnormal(0.975)
	scalar define hi`b' = e(b)[1,`b'] + sqrt(e(V)[`b',`b'])*invnormal(0.975)
	mat ci`b' = [lo`b',hi`b']
}

mat cip0 = [.,.]
foreach p of numlist 1/4 {
	local d = `p'-1
	mat rowjoin cip`p' = cip`d' ci`p' 
	}
mat cim=cip4[2..5,1..2]

mat tr1 = [1,1,2,2]'
mat tr2 = [1,2,1,2]'
mat Symp = [tr1,tr2,symp,cim]
svmat Symp
mat drop _all

generate tr12 = Symp1    if Symp2 == 1
replace  tr12 = Symp1+2.5  if Symp2 == 2

twoway (bar Symp3 tr12 if Symp1==1) (bar Symp3 tr12 if Symp1==2) (rcap Symp4 Symp5 tr12, color(black)), legend(rows(1) order(1 "Eval: Negative" 2 "Eval: Positive")) xlab(1.5 "SPP fights against WC" 4 "SPP fights for WC", noticks) xtitle("") ylab(0 (1) 9)  yscale(r(0 9)) ytitle("WC Sympathy") title("Sympathy for the Working Class") saving(symp, replace)
drop tr* Symp*

* B: SPP fights for
eststo sppfig: reg q9 i.Splitgroup1##i.Splitgroup2 if q3 !=2
margins, at(Splitgroup1=(0 1)) over(Splitgroup2) post
mat figh = e(b)'

foreach b of numlist 1/4 {
	scalar define lo`b' = e(b)[1,`b'] - sqrt(e(V)[`b',`b'])*invnormal(0.975)
	scalar define hi`b' = e(b)[1,`b'] + sqrt(e(V)[`b',`b'])*invnormal(0.975)
	mat ci`b' = [lo`b',hi`b']
}

mat cip0 = [.,.]
foreach p of numlist 1/4 {
	local d = `p'-1
	mat rowjoin cip`p' = cip`d' ci`p' 
	}
mat cim=cip4[2..5,1..2]

mat tr1 = [1,1,2,2]'
mat tr2 = [1,2,1,2]'
mat Figh = [tr1,tr2,figh,cim]
svmat Figh
mat drop _all

generate tr12 = Figh1    if Figh2 == 1
replace  tr12 = Figh1+2.5  if Figh2 == 2

twoway (bar Figh3 tr12 if Figh1==1) (bar Figh3 tr12 if Figh1==2) (rcap Figh4 Figh5 tr12, color(black)), legend(rows(1) order(1 "Eval: Negative" 2 "Eval: Positive") size(small)) xlab(1.5 "SPP fights against WC" 4 "SPP fights for WC", noticks) xtitle("") ylab(0 (1) 9)  yscale(r(0 9)) ytitle("SPP perception") title("SPP fights for the Working Class") saving(figh, replace)
drop tr* Figh*

grc1leg symp.gph figh.gph, imargin(0 0 0 0) cols(2) legendfrom(figh.gph)

* Figure 4

eststo sppvote: reg q10_1 i.Splitgroup1##i.Splitgroup2 if q3 !=2
margins, at(Splitgroup1=(0 1)) over(Splitgroup2) post
mat sympspp = e(b)'

foreach b of numlist 1/4 {
	scalar define lo`b' = e(b)[1,`b'] - sqrt(e(V)[`b',`b'])*invnormal(0.975)
	scalar define hi`b' = e(b)[1,`b'] + sqrt(e(V)[`b',`b'])*invnormal(0.975)
	mat ci`b' = [lo`b',hi`b']
}

mat cip0 = [.,.]
foreach p of numlist 1/4 {
	local d = `p'-1
	mat rowjoin cip`p' = cip`d' ci`p' 
	}
mat cim=cip4[2..5,1..2]

mat tr1 = [1,1,2,2]'
mat tr2 = [1,2,1,2]'
mat Sympspp = [tr1,tr2,sympspp,cim]
svmat Sympspp
mat drop _all

generate tr12 = Sympspp1    if Sympspp2 == 1
replace  tr12 = Sympspp1+2.5  if Sympspp2 == 2

twoway (bar Sympspp3 tr12 if Sympspp1==1) (bar Sympspp3 tr12 if Sympspp1==2) (rcap Sympspp4 Sympspp5 tr12, color(black)), legend(rows(1) order(1 "Eval: Negative" 2 "Eval: Positive")) xlab(1.5 "SPP fights against WC" 4 "SPP fights for WC", noticks) xtitle("") ylab(0 (1) 5) ytitle("PTV for SPP") title("") title(" ") saving(sympspp, replace)
graph display, ysize(4) xsize(3)
drop tr* Symp*

